import { showSuccessToast } from 'vant';
import { ref } from 'vue';

import { processOrder } from '../api';
import ProcessOrderConfig from '../models/RootConfig';

const useRootConfig = () => {
  const paramsProcessOrder = ref<ProcessOrderConfig>(new ProcessOrderConfig());
  const loading = ref(false);

  const handleProcessOrder = async () => {
    try {
      loading.value = true;
      const { data } = await processOrder(paramsProcessOrder.value);
      showSuccessToast(data.msg || '同步成功');
    } catch (error) {
      //
    } finally {
      loading.value = false;
    }
  };

  return {
    loading,
    paramsProcessOrder,
    handleProcessOrder,
  };
};

export default useRootConfig;
